
package com.trydofor.id.exec;

import com.trydofor.aloe.exception.Exceptions;
import com.trydofor.id.doer.shell.ArgHelp;
import com.trydofor.id.doer.shell.Command;
import com.trydofor.id.logs.Eventer;
import com.trydofor.id.logs.Eventer.Event;
import com.trydofor.id.logs.LogLevel;

/**
 * the commands of eventer
 * 
 * @author : Shi Rongjiu (www.trydofor.com)
 */
public final class EventerCmd {
    
    private EventerCmd() {
    }
    
    /**
     * show all registered event and its level
     * 
     * @return the command
     */
    public static Command listEventer() {
        return new Command("listEventer", "show the registerd event and its level");
    }
    
    /**
     * show all registered event and level
     * 
     * @param eventer the eventer
     * @return the command
     * @throws NullPointerException if eventer is null
     */
    public static Command changeEventer(Eventer eventer) {
        Exceptions.checkNullPointer(eventer);
        Command cmd = new Command("changeEventer", "change the registerd event's level");
        
        ArgHelp argEvent = new ArgHelp("event");
        argEvent.setManual("the event to change");
        argEvent.setRequired(true);
        argEvent.setEditable(false);
        for (Event evn : eventer.copyEventLevels().keySet()) {
            argEvent.addOption(Eventer.toFullName(evn));
        }
        cmd.addArgument(argEvent);
        
        ArgHelp argLevel = new ArgHelp("level");
        argLevel.setManual("the level to set");
        argLevel.setRequired(true);
        argLevel.setEditable(false);
        for (LogLevel lvl : LogLevel.values()) {
            //WARN
            argLevel.addOption(lvl.name());
        }
        cmd.addArgument(argLevel);
        
        return cmd;
    }
}
